package com.fhj.movie.activity;

import com.android.volley.Cache;
import com.android.volley.toolbox.ClearCacheRequest;
import com.baidu.platform.comapi.map.l;
import com.fhj.movie.view.CustomDialog;
import com.fhj.movie_fhj_01.R;
import com.lidroid.xutils.BitmapUtils;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;

public class HyySettingActivity extends Activity implements OnClickListener {
	private RelativeLayout shangwuhezuo, guanyu, welcome, clearcache,
			keFuphone, liucheng, banben;
	SelectPicPopupWindow menuWindow;
	private LinearLayout layout;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_setting);
		shangwuhezuo = (RelativeLayout) this
				.findViewById(R.id.setting_shangwuhezuo);
		guanyu = (RelativeLayout) this.findViewById(R.id.setting_guanyu);
		welcome = (RelativeLayout) this.findViewById(R.id.setting_welcome);
		clearcache = (RelativeLayout) this
				.findViewById(R.id.setting_clearcache);
		keFuphone = (RelativeLayout) this.findViewById(R.id.setting_kefuphone);
		liucheng = (RelativeLayout) this.findViewById(R.id.setting_liucheng);
		layout = (LinearLayout) this.findViewById(R.id.setting_setting);

		banben = (RelativeLayout) this.findViewById(R.id.setting_banben);
		shangwuhezuo.setOnClickListener(this);
		guanyu.setOnClickListener(this);
		welcome.setOnClickListener(this);
		clearcache.setOnClickListener(this);
		keFuphone.setOnClickListener(this);
		liucheng.setOnClickListener(this);
		banben.setOnClickListener(this);
		layout.setVisibility(View.INVISIBLE);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.setting_shangwuhezuo:
			Intent intent = new Intent(HyySettingActivity.this,
					HyyShangWuHeZuoActivity.class);
			startActivity(intent);
			layout.setVisibility(View.INVISIBLE);
			break;
		case R.id.setting_guanyu:
			Intent intent1 = new Intent(HyySettingActivity.this,
					HyyGuanYuActivity.class);
			startActivity(intent1);
			layout.setVisibility(View.INVISIBLE);
			break;
		case R.id.setting_welcome:
			Intent intent2 = new Intent(HyySettingActivity.this,
					HyyWelcomeActivity.class);
			startActivity(intent2);
			layout.setVisibility(View.INVISIBLE);
			break;
		case R.id.setting_clearcache:
			CustomDialog.Builder builder = new CustomDialog.Builder(this);
			builder.setMessage("确定清除程序的所有缓存数据吗？");
			builder.setTitle("清除缓存");
			builder.setPositiveButton("确定",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							dialog.dismiss();
							// 设置你的操作事项
							BitmapUtils bitmapUtils = new BitmapUtils(
									HyySettingActivity.this);
							bitmapUtils.clearCache();
						}
					});

			builder.setNegativeButton("取消",
					new android.content.DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							dialog.dismiss();
						}
					});

			builder.create().show();
			layout.setVisibility(View.INVISIBLE);
			break;
		case R.id.setting_kefuphone:
			menuWindow = new SelectPicPopupWindow(HyySettingActivity.this,
					itemsOnClick);
			// 显示窗口
			menuWindow.showAtLocation(
					HyySettingActivity.this.findViewById(R.id.setting_mian),
					Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
			layout.setVisibility(View.VISIBLE);
			layout.getBackground().setAlpha(125);
			break;
		case R.id.setting_liucheng:
			Intent intent3 = new Intent(HyySettingActivity.this,
					HyyItemClick.class);
			intent3.putExtra("title", "在线选票流程");
			intent3.putExtra(
					"clickUrl",
					"http://pimg1.126.net/movie/m/seatFlow.html?&login_id=B5DB834D65F49B6C8049C6D26507645386BB9EC16029FB9425909FE135569497C571DD9B5A63E9C62405FE76B7CFD03A");
			startActivity(intent3);
			layout.setVisibility(View.INVISIBLE);
			break;
		case R.id.setting_banben:
			Toast.makeText(HyySettingActivity.this, "已经是最新版本",
					Toast.LENGTH_SHORT).show();
			layout.setVisibility(View.INVISIBLE);
			break;
		default:
			break;
		}
	}

	// 为弹出窗口实现监听类
	private OnClickListener itemsOnClick = new OnClickListener() {

		public void onClick(View v) {
			menuWindow.dismiss();
			layout.getBackground().setAlpha(0);
			switch (v.getId()) {
			case R.id.cancle:
				layout.setVisibility(View.INVISIBLE);
				menuWindow.dismiss();

				break;
			case R.id.phone:
				Uri uri = Uri.parse("tel:020-83568090");
				Intent intent = new Intent(Intent.ACTION_DIAL, uri);
				startActivity(intent);
				layout.setVisibility(View.INVISIBLE);
				break;
			default:
				break;
			}

		}

	};
}
